package org.beetl.sql.core.mapper.internal;

import java.lang.reflect.Method;

import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.db.KeyHolder;
import org.beetl.sql.mapper.MapperInvoke;

public class InsertReturnKeyAmi extends MapperInvoke{

	@Override
	public Object call(SQLManager sm, Class entityClass, Method m, Object[] args) {
		// 检查args数组的长度
	    if (args == null) {
	        throw new IllegalArgumentException("args array cannot be null or empty");
	    }

	    // 处理args长度为1的情况
	    if (args.length != 1) {
	    	throw new IllegalArgumentException("args array length must be one");
	    }
	    Object obj = args[0];
	    sm.insert(entityClass,obj);
	    KeyHolder holder = KeyHolder.getKeyHolderByClass(obj);
		return holder;
	}

}
